import 'package:flutter/material.dart';

/**
 * 从节点角度,理解widget树的构建过程
 */
class HomeView extends ComponentElement{
  HomeView(Widget widget) : super(widget);
  String text = "123456789";

  @override
  Widget build() {
    print('JtTag:build:HomeView');
    Color primary=Theme.of(this).primaryColor; //1
    return Center(
      child: TextButton(
        child: Text(text, style: TextStyle(color: primary),),
        onPressed: () {
          var t = text.split("")..shuffle();
          text = t.join();
          markNeedsBuild(); //点击后将该Element标记为dirty，Element将会rebuild
        },
      ),
    );
  }
}

class CustomHome extends Widget {
  @override
  Element createElement() {
    return HomeView(this);
  }
}


class Test_Element extends StatelessWidget {
  const Test_Element({super.key});

  @override
  Widget build(BuildContext context) {
    print('JtTag:build:Test_Element');
    return Scaffold(
        appBar: AppBar(title: const Text('Test_Element')),
        body:  Column(children: [
          CustomHome()
        ])
    );
  }
}


